package com.roamer.school.repository.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.util.Date;


/**
 * 基础实体，所有entity均应当继承
 *
 * @param <T>
 *
 * @author roamer
 * @version V1.0
 * @date 2018/12/26 21:43
 */
@Data
@EqualsAndHashCode(callSuper = false)
public abstract class BaseEntity<T extends Model> extends Model<T> {

    private static final long serialVersionUID = 1L;

    /** 主键 */
    @TableId
    protected Long id;

    /** 版本号 */
    @Version
    @TableField(value = "version", fill = FieldFill.INSERT)
    protected Long version;

    /** 删除标记 */
    @TableLogic
    @TableField(value = "is_deleted", fill = FieldFill.INSERT)
    protected Boolean isDeleted;

    /** 创建时间 */
    @TableField(value = "gmt_create", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date gmtCreate;

    /** 修改时间 */
    @TableField(value = "gmt_modified", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    protected Date gmtModified;

    @Override
    protected Serializable pkVal() {
        return this.id;
    }
}
